/**
 * 最大安全数为2^53 - 1,超过会失真
*/

function add(num1, num2) {
    let result = '', data = 0
    const length = Math.max(num1.length, num2.length)
    const data1 = num1.padStart(length, 0) //03
    const data2 = num2.padStart(length, 0) //12
    for (let i = length - 1; i >= 0; i--) {
        const sum = parseInt(data1[i]) + parseInt(data2[i]) + data
        result = (sum % 10) + result
        data = Math.floor(sum / 10)
    }
    return data ? data + result : result
}
console.log(add('3', '12'))

/**
 * 方法二：BigInt
*/
const data = BigInt('123')+BigInt('123')
console.log(data.toString())
